﻿using BBCore.Core.Extensions;
using BBCore.Core.Models.Admins;
using BBCore.Core.Models.EnumTypes;
using BootstrapBlazor.Components;
using DocumentFormat.OpenXml.Spreadsheet;

namespace BBCore.Server.Components.Pages.Admins
{
    public partial class ButtonPermissionManagement
    {
        List<SelectedItem>? GetUsers { get; set; }
        private ButtonPermission ButtonPermissions { get; set; } = new();

        protected override async Task OnInitializedAsync()
        {
            GetUsers = await Fsql.Select<UserEntity>().ToListAsync(x => new SelectedItem(x.UserName!, x.UserName!));


        }
        private List<SelectedItem> GetPermissionItems(string permissions)
        {
            if (!string.IsNullOrEmpty(permissions))
            {
                //编辑
                var selectedValues = permissions.Split(',', StringSplitOptions.RemoveEmptyEntries);
                var enumList = Enum.GetValues(typeof(ButtonPermissionTypeEnum))
                                   .Cast<ButtonPermissionTypeEnum>()
                                   .Select(e => new SelectedItem { Text = e.GetDisplayName()!, Value = e.ToString(), Active = selectedValues.Contains(e.ToString()) })
                                   .ToList();
                return enumList;
                //return new List<SelectedItem>
                //{
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Add.ToString(),
                //         Text=ButtonPermissionTypeEnum.Add.GetDisplayName()!,
                //         Active=selectedValues.Contains(ButtonPermissionTypeEnum.Add.ToString())

                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Edit.ToString(),
                //         Text=ButtonPermissionTypeEnum.Edit.GetDisplayName()!,
                //         Active=selectedValues.Contains(ButtonPermissionTypeEnum.Edit.ToString())

                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Del.ToString(),
                //         Text=ButtonPermissionTypeEnum.Del.GetDisplayName()!,
                //         Active=selectedValues.Contains(ButtonPermissionTypeEnum.Del.ToString())
                //    },
                //     new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Import.ToString(),
                //         Text=ButtonPermissionTypeEnum.Import.GetDisplayName()!,
                //         Active=selectedValues.Contains(ButtonPermissionTypeEnum.Import.ToString())

                //    },
                //      new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Template.ToString(),
                //         Text=ButtonPermissionTypeEnum.Template.GetDisplayName()!,
                //         Active=selectedValues.Contains(ButtonPermissionTypeEnum.Template.ToString())

                //    }
                //};
            }
            else
            {
                //新增
                var enumList = Enum.GetValues(typeof(ButtonPermissionTypeEnum))
                                   .Cast<ButtonPermissionTypeEnum>()
                                   .Select(e => new SelectedItem { Text = e.GetDisplayName()!, Value = e.ToString() })
                                   .ToList();
                return enumList;
                //return new List<SelectedItem>
                //{
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Add.ToString(),
                //         Text=ButtonPermissionTypeEnum.Add.GetDisplayName()!
                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Edit.ToString(),
                //         Text=ButtonPermissionTypeEnum.Edit.GetDisplayName()!
                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Del.ToString(),
                //         Text=ButtonPermissionTypeEnum.Del.GetDisplayName()!
                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Import.ToString(),
                //         Text=ButtonPermissionTypeEnum.Import.GetDisplayName()!
                //    },
                //    new SelectedItem
                //    {
                //         Value=ButtonPermissionTypeEnum.Template.ToString(),
                //         Text=ButtonPermissionTypeEnum.Template.GetDisplayName()!
                //    }

                //};

            }

        }
        //private Task OnSelectedChanged(IEnumerable<SelectedItem> items, string value)
        //{

        //    ButtonPermissions.Permissions = value;
        //    //StateHasChanged();
        //    return Task.CompletedTask;
        //}


    }
}
